/***************************************************************************
 *   Copyright (C) 2007 by gaojian   *
 *   gaojian2008cnn@126.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "preferencesdialog.h"

#include "connectiondialog.h"
#include "fetchworddialog.h"
#include "settings.h"


#include <klocale.h>

#include <qlayout.h>

PreferencesDialog::PreferencesDialog(QWidget * parent)
 :  KDialogBase(Tabbed, i18n("Configure"), Ok|Apply|Help|Cancel, Ok, parent, "PreferencesDialog", true)
{
    resize(300, 400);
    enableButton( Apply, false ); 
// add pages
    QFrame *page = addPage(i18n("General"));
    QVBoxLayout *topLayout = new QVBoxLayout(page, 0, spacingHint());

    conDlg = new ConnectionDialog(page);
    topLayout->addWidget(conDlg);
    connect( conDlg, SIGNAL( configChanged() ), this, SLOT( slotChanged() ) );
// add pages
    QFrame *page2 = addPage(i18n("Fetch Word"));
    QVBoxLayout *topLayout2 = new QVBoxLayout(page2, 0, spacingHint());

    fetchDlg = new fetchWordDialog(page2);
    topLayout2->addWidget(fetchDlg);
    connect( fetchDlg, SIGNAL( configChanged() ), this, SLOT( slotChanged() ) );
   loadAllData();
   
}


PreferencesDialog::~PreferencesDialog()
{
}

void PreferencesDialog::slotChanged()
{
    changed = true;
    enableButton( Apply, true );
}

void PreferencesDialog::applySettings()
{
    conDlg->applyData();
    fetchDlg->applyData();
    kdictsettings.save();
    changed = false;
    enableButton( Apply, false );
}

void PreferencesDialog::slotOk()
{
    if ( changed )
        applySettings();
    accept();
}

void PreferencesDialog::slotCancel()
{
    if ( changed )
        loadAllData();
    reject();
}

void PreferencesDialog::slotApply()
{
    applySettings();
}

void PreferencesDialog::loadAllData()
{
    conDlg->setData();
    fetchDlg->setData();
    changed = false;
    enableButton( Apply, false );
}
#include "preferencesdialog.moc"